from django.shortcuts import render

# Create your views here.
from rest_framework.views import APIView
from random import randint
from django_redis import get_redis_connection
from meiduo_server.libs.yuntongxun.sms import CCP
from rest_framework.response import Response
import logging

logger = logging.getLogger('django')

class SMSCodeView(APIView):
    def get(self, request, moblie):
        sms_code = '%06d' % randint(0,999999)
        logger.info(sms_code)
        redis_conn = get_redis_connection('verify_codes')
        redis_conn.setex('sms_%s' % moblie,300,sms_code)
        CCP().send_template_sms(moblie, [sms_code, 5], 1)
        return Response({'message': 'ok'})
